﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace Workflow.Project
{
    public partial class UpdatePs : System.Web.UI.Page
    {
        private PJSearchManager objPJSearchManager = new PJSearchManager();
        string pjId;
        string fromWeb;
        protected void Page_Load(object sender, EventArgs e)
        {
            pjId = Request.QueryString["PJId"];
            fromWeb = Request.QueryString["FromWeb"];
            if (Session["FullName"].ToString()=="ligaoshen")
            {
                Update.Visible = true;
            }
            if(!IsPostBack)
            {
                if (fromWeb == "PJMain")
                {
                    txtPs.Text = objPJSearchManager.SearchPJMainsPs(pjId);
                }
                else if (fromWeb == "PJNode")
                {
                    txtPs.Text = objPJSearchManager.SearchPJNodesPs(pjId);
                }
                else if (fromWeb == "PJLog")
                {
                    txtPs.Text = objPJSearchManager.SearchPJLogsPs(pjId);//id
                }
            }

        }

        protected void Update_Click(object sender, EventArgs e)
        {
            try
            {
                string ps = txtPs.Text.Trim();
                if (fromWeb == "PJMain")
                {
                    objPJSearchManager.UpdatePJMainsPs(pjId, ps);
                }
                else if (fromWeb == "PJNode")
                {
                    objPJSearchManager.UpdatePJNodesPs(pjId, ps);
                }
                else if (fromWeb == "PJLog")
                {
                    objPJSearchManager.UpdatePJLogsPs(pjId, ps);//第一个参数是id
                }
                string msg = string.Format("<script>alert('保存成功！')</script>");
                string str = string.Format("<script>window.opener.location.reload();window.close();</script>");
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", str);
            }
            catch (Exception ex)
            {

                string msg = string.Format("<script>alert('{0}');</script>", ex.Message.ToString());
                Response.Write(msg);
            }
        }
    }
}